<?php

namespace app\admin\model;

use think\Model;


class Accountsend extends Model
{

    

    

    // 表名
    protected $name = 'accountsend';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'accuser',
        'optuser',
        'is_chuli_text'
    ];

    public function getIsChuliList()
    {
        return ['0' => __('Is_chuli 0'), '1' => __('Is_chuli 1'), '2' => __('Is_chuli 2')];
    }


    public function getIsChuliTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_chuli']) ? $data['is_chuli'] : '');
        $list = $this->getIsChuliList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAccuserAttr($value, $data)
    {
        $acc = Account::get($data['account_id']);
        if($acc){
            return $acc['zhanghao'].' '.$acc['name'].' '.$acc['address'];
        }
        return '';
    }

    public function getOptuserAttr($value, $data)
    {
        $user = \app\common\model\User::get($data['user_id']);
        if($user){
            return $user['nickname'].'-'.$user['username'];
        }
        return '';
    }

    public function account()
    {
        return $this->belongsTo('Account', 'account_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function accountpro()
    {
        return $this->belongsTo('Accountpro', 'accountpro_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
